<template>
  <div class="bid-info">
      <h3>
        投标截止日期：{{infoData.tenderEtimeStr}}
      </h3>
      <div class="info-div">
          <div class="info-title">
              <span>技术评标岗位</span>
          </div>
        <el-table :data="expertMan" border>
            <el-table-column label="岗位ID" align="center" prop="sysStationId"></el-table-column>
            <el-table-column label="岗位" align="center" prop="sysStationName"></el-table-column>
            <el-table-column label="公司" align="center" prop="companyName"></el-table-column>
            <el-table-column label="部门" align="center" prop="deptName"></el-table-column>           
            <el-table-column label="评标状态" align="center" prop="evaluationStatus">
                <template slot-scope="scope">
                    <TableIcon
                    :flag="scope.row.evaluationStatus"
                    :titles="[{status:0,title:'未评标'},{status:1,title:'已评标'}]"></TableIcon>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button type="text" @click="showLog(scope.row.id)">查看评分</el-button>
                </template>
            </el-table-column>
        </el-table>
      </div>

        <el-dialog title="查看评分" :visible.sync="dialogVisible" class="dialog-form" width="800px">
            <el-table :data="evalustionInfo" border>
                <el-table-column label="评分轮次" align="center" prop="quoteTimes"></el-table-column>
                <el-table-column label="评分专家" align="center" prop="expertName"></el-table-column>
                <el-table-column label="供应商编码" align="center" prop="venndorCode"></el-table-column>
                <el-table-column label="供应商名称" align="center" prop="vendorName"></el-table-column>
                <el-table-column label="评分" align="center" prop="score"></el-table-column>
                <el-table-column label="评分时间" align="center" prop="laseModifyTime"></el-table-column>
                <el-table-column label="评分附件" align="center" prop="techAttachName">
                    <template slot-scope="scope">
                        <a href="#">评分附件</a>
                    </template>
                </el-table-column>
                <el-table-column label="描述" align="center" prop="evaluationRemarks"></el-table-column>
            </el-table>
            <div slot="footer" class="dialog-footer"></div>
        </el-dialog>

        <div class="info-div br0">
            <div class="info-title">
              <span>评标结果汇总表</span>
              <el-button size="mini" @click="openTech" style="margin-left:20px" v-if="infoData.submitCompStatus==1&&infoData.evaluationStatus==0">查看技术澄清</el-button>
              <el-button size="mini" type="primary" @click="showEdit" v-if="infoData.submitCompStatus==1&&infoData.evaluationStatus==0">技术澄清</el-button>
            </div>
            <el-table :data="evalustionResult" border @selection-change="getIds">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column label="供应商" align="center" prop="vendorName"></el-table-column>
                <el-table-column label="技术分" align="center" prop="techScore"></el-table-column>
                <el-table-column label="技术排名" align="center" prop="techSequence"></el-table-column>
                <el-table-column label="商务分" align="center" prop="businessScore"></el-table-column>
                <el-table-column label="商务排名" align="center" prop="businessSequence"></el-table-column>
                <el-table-column label="总分" align="center" prop="totalScore"></el-table-column>
                <el-table-column label="总排名" align="center" prop="totalSequence"></el-table-column>
                <el-table-column label="总价" align="center" prop="totalPrice">
                    <template slot-scope="scope">
                        <!-- <el-button type="text" @click="showInfos">{{scope.row.vendorAddress}}</el-button> -->
                    </template>
                </el-table-column>
                <el-table-column label="价格排名" align="center" prop="priceSequence"></el-table-column>
            </el-table>
        </div>

        <el-dialog title="报价轮次" :visible.sync="infosVisible" class="dialog-form">
            <el-table :data="evalustionInfo" border>
                <el-table-column label="序号" align="center" prop="1"></el-table-column>
                <el-table-column label="轮次" align="center" prop="quoetTimes"></el-table-column>
                <el-table-column label="含税单价" align="center" prop="taxPrice"></el-table-column>
            </el-table>
            <div slot="footer" class="dialog-footer"></div>
        </el-dialog>

        <el-dialog title="技术澄清" :visible.sync="editVisible" width="800px">
            <el-form :model="editData" :rules="rules" ref="editData" label-width="130px" class="demo-ruleForm">
                <el-form-item label="标题：" prop="clarifyTitle">
                    <el-input v-model="editData.clarifyTitle"></el-input>
                </el-form-item>
                <el-form-item label="类型：" prop="clarifyType">
                    <el-radio-group v-model="editData.clarifyType">
                        <el-radio label="1">技术</el-radio>
                        <el-radio label="2">商务</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="澄清内容：" prop="clarifyContent">
                    <el-input v-model="editData.clarifyContent" type="textarea"></el-input>
                </el-form-item> 
                <el-form-item label="附件：" prop="clarifyAttUrl">
                    <el-upload class="upload-file" ref="upload" :action="this.lib.config.host.system + '/common/fileupload/upload'" :data="fileData"
                    :limit="1" :on-success="res=>{uploadSuccess(res,'clarifyAttUrl')}" :file-list="fileList">
                    <el-button slot="trigger" type="primary">选取文件</el-button>
                    </el-upload>
                </el-form-item>
                <el-form-item label="是否要求响应：" prop="isNeedFeedback">
                    <el-radio-group v-model="editData.isNeedFeedback">
                        <el-radio label="0">否</el-radio>
                        <el-radio label="1">是</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="响应截止时间：" prop="feedbackEndtime" v-if="editData.isNeedFeedback==1">
                    <el-date-picker v-model="editData.feedbackEndtime" 
                        type="date" value-format="yyyy-MM-dd" placeholder="截止时间" 
                        :picker-options="pickeroptions" 
                        >
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="供应商：" prop="isNeedTecbidding">
                    <el-radio-group v-model="editData.isNeedTecbidding">
                        <el-radio label="2">指定</el-radio>
                        <el-radio label="1">全体</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="指定供应商：" v-if="editData.isNeedTecbidding==2">
                     <el-table :data="ids" border>
                        <el-table-column label="供应商编码" align="center" prop="vendorCode"></el-table-column>
                        <el-table-column label="供应商名称" align="center" prop="vendorName"></el-table-column>
                    </el-table> 
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm">提交</el-button>
                    <el-button @click="editVisible=false">取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
  </div>
</template>
<script>
  import TableIcon from '@/components/common/table-ext/table-icon';
  export default {
    components:{
      TableIcon
    },
    props:['stepData'],
    data() {
      return {
          fileData: {
            busAction: "BID_SET_EVA_METHOD",
            tableName: "CT_PS_BID_MAIN_EXT",
            tableId: this.$route.query.id
          },
          fileList:[],
          dialogVisible:false,
          editVisible:false,
          infosVisible:false,
          ids:[],
          expertMan:[],
          evalustionResult:[],
          evalustionInfo:[],
          remarks:'',
          tableData:[],
          infoData:{},
          rules:{
            clarifyTitle: [{
                required:true,
                message: '请填写标题',
                trigger: 'blur'
            }],
            clarifyAttUrl: [{
                required:true,
                message: '请上传附件',
                trigger: 'change'
            }],
            feedbackEndtime: [{
                required:true,
                message: '请选择响应截止时间',
                trigger: 'change'
            }],
            clarifyContent: [{
                required:true,
                message: '请填写澄清内容',
                trigger: 'blur'
            }],
            clarifyType:[],
            isNeedFeedback:[],
            isNeedTecbidding:[],
          },
          editData:{
            clarifyTitle:'', 
            clarifyType:'1', 
            clarifyContent:'', 
            clarifyAttUrl:'', 
            isNeedFeedback:'0', 
            feedbackEndtime:'', 
            isNeedTecbidding:'2',
          },
          pickeroptions:{
            disabledDate(time) {
                return time.getTime() <= Date.now()- 8.64e7
            }
          }
      };
    },
    mounted(){
        this.infoData=this.stepData.bidMainDto;
    },
    created(){
        this.queryEvaStation();
        this.queryEvalustionResult();
    },
    methods: {
        uploadSuccess: function (response,type) {
            //附件上传成功回调
            this.editData[type] = response.id;
        },
        queryEvalustionResult(){
            //查看评标结果（评分）
            this.axios.post(`${this.lib.config.host.bidtender}/bidmgt/view/queryEvalustionResult/${this.$attrs.data.id}`).then((res) => {
                this.evalustionResult=res.data;
            }).catch(function (error) {
                console.log(error);
            });
        },
        queryEvaStation(){
            //查看评标
            this.axios.post(`${this.lib.config.host.bidtender}/bidmgt/view/queryEvaStation/${this.$attrs.data.id}/1`).then((res) => {
                this.expertMan=res.data;
            }).catch(function (error) {
                console.log(error);
            });
        },
        showEdit(){
            if(!this.ids.length){
                this.$message.info('请先选择需要技术澄清的评标结果！')
                return;
            }
            this.editVisible=true;
            this.$nextTick(()=>{
                this.resetForm('editData')
            })
        },
        getIds(rows){
            this.ids=rows;
        },
        showLog(id){
            //获取评分
            this.axios.post(`${this.lib.config.host.bidtender}/bidmgt/view/queryEvalustion/${this.$attrs.data.id}/${id}`).then((res) => {
                this.evalustionInfo=res.data;
                this.dialogVisible=true;
            }).catch(function (error) {
                console.log(error);
            });
        },
        showInfos(id){
            this.infosVisible=true;
        },
        openTech(){
            window.open(`./techInstruction?id=${this.$attrs.data.id}`)
        },
        submitForm(){
            this.$refs.editData.validate((vaild)=>{
                if(vaild){
                    let data={...this.editData}
                    //技术澄清
                    this.axios.post(`${this.lib.config.host.bidtender}/bidmgt/addition/saveClarify/${this.$attrs.data.id}`,data).then((res) => {
                        if(res.data.success){
                            this.$emit('initList');
                            this.queryEvaStation();
                            this.$message.success('提交成功！');
                            this.editVisible=false;
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
                }
            })
        }
    }
  }

</script>
